<?php
/**
 *  Moduleicon.php
 *
 *  @author     {$author}
 *  @package    Xanhte
 *  @version    $Id: Moduleicon.php 195 2008-03-01 15:34:44Z mikhail.miguel $
 */

/**
 *  indexビューの実装
 *
 *  @author     {$author}
 *  @access     public
 *  @package    Xanhte
 */
class Xanhte_View_Moduleicon extends Xanhte_ViewClass
{
    /**
     *  遷移前処理
     *
     *  @access public
     */
    function preforward()
    {
		$dirname = $this->af->get('dirname');
		
		$icon_cache_limit = 3600 ; // default 3600sec == 1hour
		
		session_cache_limiter('public');
		header("Expires: ".date('r',intval(time()/$icon_cache_limit)*$icon_cache_limit+$icon_cache_limit));
		header("Cache-Control: public, max-age=$icon_cache_limit");
		header("Last-Modified: ".date('r',intval(time()/$icon_cache_limit)*$icon_cache_limit));
		header("Content-type: image/png");
		
		$custom_icon = sprintf('%s/modules/%s/module_icon.png',
							   XOOPS_ROOT_PATH, $dirname);
		$base_icon = BASE.'/skel/skel.module_icon.png'; // BASE is ethna_base directory
		
		if(! file_exists($custom_icon) &&
		   function_exists( 'imagecreatefrompng' ) &&
		   function_exists( 'imagecolorallocate' ) &&
		   function_exists( 'imagestring' ) &&
		   function_exists( 'imagepng' ) ) {
			
			$im = imagecreatefrompng( $base_icon ) ;
			
			$color = imagecolorallocate( $im , 10 , 14 , 138 ) ; // blue
			$px = ( 127 - 6 * strlen( $dirname ) ) / 2 ;
			imagestring( $im , 3 , $px , 5 , $dirname , $color ) ;
			imagepng( $im ) ;
			imagedestroy( $im ) ;
		} else {
			readfile( $custom_icon ) ;
		}
	}
	
	function forward()
	{
		exit;
	}
	
}
